cn
en
1 让自己习惯c++
accustoming yourself to c++
01:视c++ 为一个语言联邦
view c++ as a federation of languages
02:尽量以const, enum, inline替换 #define
prefer consts,enums, and inlines to #defines
03:尽可能使用const
use const whenever possible
04:确定对象被使用前已先被初始化
make sure that objects are initialized before they're used
2 构造/析构/赋值运算
constructors, destructors, and assignment operators
05:了解c++ 默默编写并调用哪些函数
know what functions c++ silently writes and calls
06:若不想使用编译器自动生成的函数,就该明确拒绝
explicitly disallow the use of compiler-generated functions you do not want
07:为多态基类声明virtual析构函数
declare destructors virtual in polymorphic base classes
08:别让异常逃离析构函数
prevent exceptions from leaving destructors
09:绝不在构造和析构过程中调用virtual函数
never call virtual functions during construction or destruction
10:令operator= 返回一个reference to *this
have assignment operators return a reference to *this
11:在operator= 中处理“自我赋值”
handle assignment to self in operator=
12:复制对象时勿忘其每一个成分
copy all parts of an object
3 资源管理
resource management
13:以对象管理资源
use objects to manage resources
14:在资源管理类中小心copying行为
think carefully about copying behavior in resource-managing classes
15:在资源管理类中提供对原始资源的访问
provide access to raw resources in resource-managing classes
16:成对使用new和delete时要采取相同形式
use the same form in corresponding uses of new and delete
17:以独立语句将newed对象置入智能指针
store newed objects in smart pointers in standalone statements
4 设计与声明
designs and declarations
18:让接口容易被正确使用,不易被误用
make interfaces easy to use correctly and hard to use incorrectly
19:设计class犹如设计type
treat class design as type design
20:宁以pass-by-reference-to-const替换pass-by-value
prefer pass-by-reference-to-const to pass-by-value
21:必须返回对象时,别妄想返回其reference
don't try to return a reference when you must return an object
22:将成员变量声明为private
declare data members private
23:宁以non-member、non-friend替换member函数
prefer non-member non-friend functions to member functions
24:若所有参数皆需类型转换,请为此采用non-member函数
declare non-member functions when type conversions should apply to all parameters
25:考虑写出一个不抛异常的swap函数
consider support for a non-throwing swap
5 实现
implementations
26:尽可能延后变量定义式的出现时间
postpone variable definitions as long as possible
27:尽量少做转型动作
minimize casting
28:避免返回handles指向对象内部成分
avoid returning "handles" to object internals
29:为“异常安全”而努力是值得的
strive for exception-safe code
30:透彻了解inlining的里里外外
understand the ins and outs of inlining
31:将文件间的编译依存关系降至最低
minimize compilation dependencies between files
6 继承与面向对象设计
inheritance and object-oriented design
32:确定你的public继承塑模出is-a关系
make sure public inheritance models "is-a "
33:避免遮掩继承而来的名称
avoid hiding inherited names
34:区分接口继承和实现继承
differentiate between inheritance of interface and inheritance of implementation
35:考虑virtual函数以外的其他选择
consider alternatives to virtual functions
36:绝不重新定义继承而来的non-virtual函数
never redefine an inherited non-virtual function
37:绝不重新定义继承而来的缺省参数值
never redefine a function's inherited default parameter value
38:通过复合塑模出has-a或"根据某物实现出"
model "has-a" or "is-implemented-in-terms-of" through composition
39:明智而审慎地使用private继承
use private inheritance judiciously
40:明智而审慎地使用多重继承
use multiple inheritance judiciously
7 模板与泛型编程
templates and generic programming
41:了解隐式接口和编译期多态
understand implicit interfaces and compile-time polymorphism
42:了解typename的双重意义
understand the two meanings of typename
43:学习处理模板化基类内的名称
know how to access names in templatized base classes
44:将与参数无关的代码抽离templates
factor parameter-independent code out of templates
45:运用成员函数模板接受所有兼容类型
use member function templates to accept "all compatible types "
46:需要类型转换时请为模板定义非成员函数
define non-member functions inside templates when type conversions are desired
47:请使用traits classes表现类型信息
use traits classes for information about types
48:认识template元编程
be aware of template metaprogramming
8 定制new和delete
customizing new and delete
49:了解new-handler的行为
understand the behavior of the new-handler
50:了解new和delete的合理替换时机
understand when it makes sense to replace new and delete
51:编写new和delete时需固守常规
adhere to convention when writing new and delete
52:写了placement new也要写placement delete
write placement delete if you write placement new
9 杂项讨论
miscellany
53:不要轻忽编译器的警告
pay attention to compiler warnings
54:让自己熟悉包括tr1在内的标准程序库
familiarize yourself with the standard library, including tr1
55:让自己熟悉boost
familiarize yourself with boost